package com.liip.app.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

import com.liip.app.task.JobTask;

import lombok.extern.slf4j.Slf4j;


/**
 * WebSocketConfig 配置信息
 * @Auther: luolin
 * @Date: 2020-11-03 8:06 PM
 * @Description:
 */
@Controller
@Slf4j
public class WsController {
	/**
	 * @SendTo 注解外,Spring 还提供了 SimpMessagingTemplate 类
	 * SimpMessagingTemplate是Spring-WebSocket内置的一个消息发送工具，可以将消息发送到指定的客户端
	 */
	@Autowired
    private SimpMessagingTemplate messagingTemplate;

    @MessageMapping("/chat")
    @SendTo("/queue/notice")//接收/app/chat发来的msg，然后将msg转发到/topic/notice客户端
    public String handleChat(String msg) {
         log.info("/chat："+msg);
         return "/queue/notice" + msg;
            //messagingTemplate.convertAndSendToUser("lenve", "/queue/notifications,给您发来了消息：" + msg);
       
            //messagingTemplate.convertAndSendToUser("sang", "/queue/notifications,给您发来了消息：" + msg);
       
    }
}
